<?php
$config = include_once('../../public/config/config.php');
include_once('../../public/func/db.php');
include_once('../../public/func/upload.func.php');
$array = array(
	'uname' => '用户名',
	'pwd' => '密码',
	'nickname' => '昵称',
	'email' => '邮箱',
);
foreach($_POST as $k=>$v){
	if(!$v){
		echo '<script>alert("'.$array[$k].'不能为空");window.location.href="/admin/user/add.php"</script>';
	}
}
//判断用户名是否为空
if(!$_POST['uname']){
	echo '<script>alert("用户名不能为空");window.location.href="/admin/user/add.php"</script>';
}
$post = $_POST;
if($_FILES['pic']['error'] != 4){
	$path = '../../public/upload';
	$post['pic'] = upload($_FILES['pic'],$path);
}else{
	$post['pic'] = 'default.jpg';
}
$table = 'user';
$post['ctime'] = time();
$post['pwd'] = md5($_POST['pwd']);
$res = insert($config,$table,$post);
if($res == ''){
	echo '<script>alert("添加成功");window.location.href="/admin/user/index.php"</script>';
}else{
	echo '<script>alert("添加失败");window.location.href="/admin/user/add.php"</script>';
}








// // 判断密码是否为空
// if(!$_POST['nickname']){
// 	echo '<script>alert("昵称不能为空");window.location.href="/admin/user/add.php"</script>';
// }
// // 判断昵称是否为空
// if(!$_POST['pwd']){
// 	echo '<script>alert("密码不能为空");window.location.href="/admin/user/add.php"</script>';
// }
// // 判断邮箱是否为空
// if(!$_POST['email']){
// 	echo '<script>alert("邮箱不能为空");window.location.href="/admin/user/add.php"</script>';
// }